package com.twetec.cms.dao.mapper.website;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.twetec.cms.model.po.website.ArticlePO;
import com.twetec.cms.model.po.website.ColumnReferenceArticlePO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 文章表 Mapper 接口
 * </p>
 *
 * @author zhxl
 * @since 2021-10-08
 */
public interface ArticleMapper extends BaseMapper<ArticlePO> {
    
    @Select("SELECT\n" +
            " *\n" +
            "FROM\n" +
            " (\n" +
            "  SELECT\n" +
            "   ID,\n" +
            "   SITE_ID,\n" +
            "   COLUMN_ID,\n" +
            "   TITLE,\n" +
            "   SUMMARY,\n" +
            "   ATTRIBUTE,\n" +
            "   RELEASE_CHANNEL,\n" +
            "   RELEASE_TIME,\n" +
            "   GMT_ANNOUNCEMENT_START,\n" +
            "   GMT_ANNOUNCEMENT_END,\n" +
            "   COVER,\n" +
            "   COVER_TYPE,\n" +
            "   SORT,\n" +
            "   SORT_TYPE,\n" +
            "   ARTICLE_STATUS,\n" +
            "   IS_RECOVERY,\n" +
            "   VERIFY_REASON,\n" +
            "   CREATOR_ID,\n" +
            "   MODIFIER_ID,\n" +
            "   GMT_CREATE,\n" +
            "   GMT_MODIFIED,\n" +
            "   IS_DELETED,\n" +
            "   DATA_ORG,\n" +
            "   VERSION,\n" +
            "   TYPE,\n" +
            "   ORIGIN,\n" +
            "   AUTHOR,\n" +
            "   '引用文章' AS ARTICLE_TYPE\n" +
            "  FROM\n" +
            "   ARTICLE\n" +
            "  UNION\n" +
            "   SELECT\n" +
            "    ARTICLE.ID,\n" +
            "    ARTICLE.SITE_ID,\n" +
            "    COLUMN_REFERENCE_ARTICLE.CURRENT_COLUMN_ID AS COLUMN_ID,\n" +
            "    ARTICLE.TITLE,\n" +
            "    ARTICLE.SUMMARY,\n" +
            "    ARTICLE.ATTRIBUTE,\n" +
            "    ARTICLE.RELEASE_CHANNEL,\n" +
            "    ARTICLE.RELEASE_TIME,\n" +
            "    ARTICLE.GMT_ANNOUNCEMENT_START,\n" +
            "    ARTICLE.GMT_ANNOUNCEMENT_END,\n" +
            "    ARTICLE.COVER,\n" +
            "    ARTICLE.COVER_TYPE,\n" +
            "    ARTICLE.SORT,\n" +
            "    ARTICLE.SORT_TYPE,\n" +
            "    COLUMN_REFERENCE_ARTICLE.REFERENCE_ARTICLE_STATUS AS ARTICLE_STATUS,\n" +
            "    ARTICLE.IS_RECOVERY,\n" +
            "    ARTICLE.VERIFY_REASON,\n" +
            "    ARTICLE.CREATOR_ID,\n" +
            "    ARTICLE.MODIFIER_ID,\n" +
            "    ARTICLE.GMT_CREATE,\n" +
            "    ARTICLE.GMT_MODIFIED,\n" +
            "    ARTICLE.IS_DELETED,\n" +
            "    ARTICLE.DATA_ORG,\n" +
            "    ARTICLE.VERSION,\n" +
            "    ARTICLE.TYPE,\n" +
            "    ARTICLE.ORIGIN,\n" +
            "    ARTICLE.AUTHOR,\n" +
            "   '引用文章' AS ARTICLE_TYPE\n" +
            "   FROM\n" +
            "    COLUMN_REFERENCE_ARTICLE\n" +
            "   LEFT JOIN ARTICLE ON ARTICLE. ID = COLUMN_REFERENCE_ARTICLE.REFERENCE_ARTICLE_ID\n" +
            " )\n" +
            "${ew.customSqlSegment}")
    Page<ArticlePO> getReferenceArticle(Page<ArticlePO> page, @Param(Constants.WRAPPER) QueryWrapper<ArticlePO> queryWrapper);

}
